home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_08 / phillip2 / fitt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-20  |  17.2 KB  |  650 lines

  1. /* (C) Copr. 1986-92 Numerical Recipes Software  */
  2.  
  3.  
  4.    /********************************************
  5.    *
  6.    *   This file contains code from the 
  7.    *   Numerical Recipies in C text by
  8.    *   Press, Flannery, Teukolsky, Vetterling
  9.    *   I needed the routines to fit data to
  10.    *   a straight line y=mx+b.
  11.    *
  12.    *
  13.    *   This files contains the files:
  14.    *      nrutil.h
  15.    *      fit.c
  16.    *      gammq.c
  17.    *      gcf.c
  18.    *      gser.c
  19.    *      gammln.c
  20.    *      nrutil.c
  21.    *
  22.    *   21 August 1993
  23.    *
  24.    ********************************************/
  25.  
  26.  
  27.  
  28.  
  29. #include <math.h>
  30.  
  31.    /* file nrutil.h */
  32.  
  33. #ifndef _NR_UTILS_H_
  34. #define _NR_UTILS_H_
  35.  
  36. static float sqrarg;
  37. #define SQR(a) ((sqrarg=(a)) == 0.0 ? 0.0 : sqrarg*sqrarg)
  38.  
  39. static double dsqrarg;
  40. #define DSQR(a) ((dsqrarg=(a)) == 0.0 ? 0.0 : dsqrarg*dsqrarg)
  41.  
  42. static double dmaxarg1,dmaxarg2;
  43. #define DMAX(a,b) (dmaxarg1=(a),dmaxarg2=(b),(dmaxarg1) > (dmaxarg2) ?\
  44.         (dmaxarg1) : (dmaxarg2))
  45.  
  46. static double dminarg1,dminarg2;
  47. #define DMIN(a,b) (dminarg1=(a),dminarg2=(b),(dminarg1) < (dminarg2) ?\
  48.         (dminarg1) : (dminarg2))
  49.  
  50. static float maxarg1,maxarg2;
  51. #define FMAX(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1) > (maxarg2) ?\
  52.         (maxarg1) : (maxarg2))
  53.  
  54. static float minarg1,minarg2;
  55. #define FMIN(a,b) (minarg1=(a),minarg2=(b),(minarg1) < (minarg2) ?\
  56.         (minarg1) : (minarg2))
  57.  
  58. static long lmaxarg1,lmaxarg2;
  59. #define LMAX(a,b) (lmaxarg1=(a),lmaxarg2=(b),(lmaxarg1) > (lmaxarg2) ?\
  60.         (lmaxarg1) : (lmaxarg2))
  61.  
  62. static long lminarg1,lminarg2;
  63. #define LMIN(a,b) (lminarg1=(a),lminarg2=(b),(lminarg1) < (lminarg2) ?\
  64.         (lminarg1) : (lminarg2))
  65.  
  66. static int imaxarg1,imaxarg2;
  67. #define IMAX(a,b) (imaxarg1=(a),imaxarg2=(b),(imaxarg1) > (imaxarg2) ?\
  68.         (imaxarg1) : (imaxarg2))
  69.  
  70. static int iminarg1,iminarg2;
  71. #define IMIN(a,b) (iminarg1=(a),iminarg2=(b),(iminarg1) < (iminarg2) ?\
  72.         (iminarg1) : (iminarg2))
  73.  
  74. #define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a))
  75.  
  76. #if defined(__STDC__) || defined(ANSI) || defined(NRANSI) /* ANSI */
  77.  
  78. void nrerror(char error_text[]);
  79. float *vector(long nl, long nh);
  80. int *ivector(long nl, long nh);
  81. unsigned char *cvector(long nl, long nh);
  82. unsigned long *lvector(long nl, long nh);
  83. double *dvector(long nl, long nh);
  84. float **matrix(long nrl, long nrh, long ncl, long nch);
  85. double **dmatrix(long nrl, long nrh, long ncl, long nch);
  86. int **imatrix(long nrl, long nrh, long ncl, long nch);
  87. float **submatrix(float **a, long oldrl, long oldrh, long oldcl, long oldch,
  88.    long newrl, long newcl);
  89. float **convert_matrix(float *a, long nrl, long nrh, long ncl, long nch);
  90. float ***f3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh);
  91. void free_vector(float *v, long nl, long nh);
  92. void free_ivector(int *v, long nl, long nh);
  93. void free_cvector(unsigned char *v, long nl, long nh);
  94. void free_lvector(unsigned long *v, long nl, long nh);
  95. void free_dvector(double *v, long nl, long nh);
  96. void free_matrix(float **m, long nrl, long nrh, long ncl, long nch);
  97. void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch);
  98. void free_imatrix(int **m, long nrl, long nrh, long ncl, long nch);
  99. void free_submatrix(float **b, long nrl, long nrh, long ncl, long nch);
  100. void free_convert_matrix(float **b, long nrl, long nrh, long ncl, long nch);
  101. void free_f3tensor(float ***t, long nrl, long nrh, long ncl, long nch,
  102.    long ndl, long ndh);
  103.  
  104. #else /* ANSI */
  105. /* traditional - K&R */
  106.  
  107. void nrerror();
  108. float *vector();
  109. float **matrix();
  110. float **submatrix();
  111. float **convert_matrix();
  112. float ***f3tensor();
  113. double *dvector();
  114. double **dmatrix();
  115. int *ivector();
  116. int **imatrix();
  117. unsigned char *cvector();
  118. unsigned long *lvector();
  119. void free_vector();
  120. void free_dvector();
  121. void free_ivector();
  122. void free_cvector();
  123. void free_lvector();
  124. void free_matrix();
  125. void free_submatrix();
  126. void free_convert_matrix();
  127. void free_dmatrix();
  128. void free_imatrix();
  129. void free_f3tensor();
  130.  
  131. #endif /* ANSI */
  132.  
  133. #endif /* _NR_UTILS_H_ */
  134.  
  135.  
  136.  
  137.  
  138.  
  139.    /* file fit.c */
  140.  
  141.  
  142. #undef  DDEBUG
  143. #define NRANSI
  144.  
  145. void fit(float x[], float y[], int ndata, float sig[], int mwt, float *a,
  146.    float *b, float *siga, float *sigb, float *chi2, float *q)
  147. {
  148.    float gammq(float a, float x);
  149.    int i;
  150.    float wt,t,sxoss,sx=0.0,sy=0.0,st2=0.0,ss,sigdat;
  151.  
  152. int iii;
  153. #ifdef DDEBUG
  154. printf("\nDEBUG> ndata=%d mwt=%d", ndata, mwt);
  155. for(iii=1; iii<=ndata; iii++)
  156. printf("\nDEBUG> x=%f y=%f sig=%f",x[iii],y[iii],sig[iii]);
  157. printf("\nDEBUG> start of fit");
  158. #endif DDEBUG
  159.  
  160. /* 
  161.    change 8-21-93
  162.    The sig array is all 1's so I will remove
  163.    all uses of it in mult and division.
  164. */
  165.  
  166.    *b=0.0;
  167.    if (mwt) {
  168.       ss=0.0;
  169.       for (i=1;i<=ndata;i++) {
  170.          wt=1.0;
  171.          ss += wt;
  172.          sx += x[i]*wt;
  173.          sy += y[i]*wt;
  174.       }
  175.    } else {
  176.       for (i=1;i<=ndata;i++) {
  177.          sx += x[i];
  178.          sy += y[i];
  179.       }
  180.       ss=ndata;
  181.    }
  182.    sxoss=sx/ss;
  183.    if (mwt) {
  184.       for (i=1;i<=ndata;i++) {
  185.          t=(x[i]-sxoss);
  186.          st2 += t*t;
  187.          *b += t*y[i];
  188.       }
  189.    } else {
  190.       for (i=1;i<=ndata;i++) {
  191.          t=x[i]-sxoss;
  192.          st2 += t*t;
  193.          *b += t*y[i];
  194.       }
  195.    }
  196.    *b /= st2;
  197.    *a=(sy-sx*(*b))/ss;
  198.    *siga=sqrt((1.0+sx*sx/(ss*st2))/ss);
  199.    *sigb=sqrt(1.0/st2);
  200.    *chi2=0.0;
  201.    if (mwt == 0) {
  202.       for (i=1;i<=ndata;i++)
  203.          *chi2 += SQR(y[i]-(*a)-(*b)*x[i]);
  204.       *q=1.0;
  205.       sigdat=sqrt((*chi2)/(ndata-2));
  206.       *siga *= sigdat;
  207.       *sigb *= sigdat;
  208.    } else {
  209.       for (i=1;i<=ndata;i++)
  210.          *chi2 += SQR((y[i]-(*a)-(*b)*x[i]));
  211.       *q=gammq(0.5*(ndata-2),0.5*(*chi2));
  212.    }
  213. }
  214. #undef NRANSI
  215.  
  216.  
  217.  
  218.  
  219.  
  220.    /* file gammq.c */
  221.  
  222. /* (C) Copr. 1986-92 Numerical Recipes Software $|9`0S[)03. */
  223. float gammq(float a, float x)
  224. {
  225.    void gcf(float *gammcf, float a, float x, float *gln);
  226.    void gser(float *gamser, float a, float x, float *gln);
  227.    void nrerror(char error_text[]);
  228.    float gamser,gammcf,gln;
  229.  
  230.    if (x < 0.0 || a <= 0.0) nrerror("Invalid arguments in routine gammq");
  231.    if (x < (a+1.0)) {
  232.       gser(&gamser,a,x,&gln);
  233.       return 1.0-gamser;
  234.    } else {
  235.       gcf(&gammcf,a,x,&gln);
  236.       return gammcf;
  237.    }
  238. }
  239.  
  240.  
  241.  
  242.  
  243.  
  244.    /* file gcf.c */
  245.  
  246. /* (C) Copr. 1986-92 Numerical Recipes Software $|9`0S[)03. */
  247. #define ITMAX 100
  248. #define EPS 3.0e-7
  249. #define FPMIN 1.0e-30
  250.  
  251. void gcf(float *gammcf, float a, float x, float *gln)
  252. {
  253.    float gammln(float xx);
  254.    void nrerror(char error_text[]);
  255.    int i;
  256.    float an,b,c,d,del,h;
  257.  
  258.    *gln=gammln(a);
  259.    b=x+1.0-a;
  260.    c=1.0/FPMIN;
  261.    d=1.0/b;
  262.    h=d;
  263.    for (i=1;i<=ITMAX;i++) {
  264.       an = -i*(i-a);
  265.       b += 2.0;
  266.       d=an*d+b;
  267.       if (fabs(d) < FPMIN) d=FPMIN;
  268.       c=b+an/c;
  269.       if (fabs(c) < FPMIN) c=FPMIN;
  270.       d=1.0/d;
  271.       del=d*c;
  272.       h *= del;
  273.       if (fabs(del-1.0) < EPS) break;
  274.    }
  275.    if (i > ITMAX) nrerror("a too large, ITMAX too small in gcf");
  276.    *gammcf=exp(-x+a*log(x)-(*gln))*h;
  277. }
  278. #undef ITMAX
  279. #undef EPS
  280. #undef FPMIN
  281.  
  282.  
  283.  
  284.  
  285.  
  286.    /* file gser.c */
  287.  
  288. /* (C) Copr. 1986-92 Numerical Recipes Software $|9`0S[)03. */
  289. #define ITMAX 100
  290. #define EPS 3.0e-7
  291.  
  292. void gser(float *gamser, float a, float x, float *gln)
  293. {
  294.    float gammln(float xx);
  295.    void nrerror(char error_text[]);
  296.    int n;
  297.    float sum,del,ap;
  298.  
  299.    *gln=gammln(a);
  300.    if (x <= 0.0) {
  301.       if (x < 0.0) nrerror("x less than 0 in routine gser");
  302.       *gamser=0.0;
  303.       return;
  304.    } else {
  305.       ap=a;
  306.       del=sum=1.0/a;
  307.       for (n=1;n<=ITMAX;n++) {
  308.          ++ap;
  309.          del *= x/ap;
  310.          sum += del;
  311.          if (fabs(del) < fabs(sum)*EPS) {
  312.             *gamser=sum*exp(-x+a*log(x)-(*gln));
  313.             return;
  314.          }
  315.       }
  316.       nrerror("a too large, ITMAX too small in routine gser");
  317.       return;
  318.    }
  319. }
  320. #undef ITMAX
  321. #undef EPS
  322.  
  323.  
  324.  
  325.  
  326.  
  327.    /* file gammln.c */
  328.  
  329. /* (C) Copr. 1986-92 Numerical Recipes Software $|9`0S[)03. */
  330.  
  331. float gammln(float xx)
  332. {
  333.    double x,y,tmp,ser;
  334.    static double cof[6]={76.18009172947146,-86.50532032941677,
  335.       24.01409824083091,-1.231739572450155,
  336.       0.1208650973866179e-2,-0.5395239384953e-5};
  337.    int j;
  338.  
  339.    y=x=xx;
  340.    tmp=x+5.5;
  341.    tmp -= (x+0.5)*log(tmp);
  342.    ser=1.000000000190015;
  343.    for (j=0;j<=5;j++) ser += cof[j]/++y;
  344.    return -tmp+log(2.5066282746310005*ser/x);
  345. }
  346.  
  347.  
  348.  
  349.  
  350. /* (C) Copr. 1986-92 Numerical Recipes Software $|9`0S[)03. */
  351.  
  352.  
  353.    /* file nrutil.c */
  354.  
  355.  
  356. /* CAUTION: This is the ANSI C (only) version of the Numerical Recipes
  357.    utility file nrutil.c.  Do not confuse this file with the same-named
  358.    file nrutil.c that is supplied in the same subdirectory or archive
  359.    as the header file nrutil.h.  *That* file contains both ANSI and
  360.    traditional K&R versions, along with #ifdef macros to select the
  361.    correct version.  *This* file contains only ANSI C.               */
  362.  
  363. #include <stdio.h>
  364. #include <stddef.h>
  365. #include <stdlib.h>
  366. #define NR_END 1
  367. #define FREE_ARG char*
  368.  
  369. void nrerror(char error_text[])
  370. /* Numerical Recipes standard error handler */
  371. {
  372.    fprintf(stderr,"Numerical Recipes run-time error...\n");
  373.    fprintf(stderr,"%s\n",error_text);
  374.    fprintf(stderr,"...now exiting to system...\n");
  375.    exit(1);
  376. }
  377.  
  378. float *vector(long nl, long nh)
  379. /* allocate a float vector with subscript range v[nl..nh] */
  380. {
  381.    float *v;
  382.  
  383.    v=(float *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(float)));
  384.    if (!v) nrerror("allocation failure in vector()");
  385.    return v-nl+NR_END;
  386. }
  387.  
  388. int *ivector(long nl, long nh)
  389. /* allocate an int vector with subscript range v[nl..nh] */
  390. {
  391.    int *v;
  392.  
  393.    v=(int *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(int)));
  394.    if (!v) nrerror("allocation failure in ivector()");
  395.    return v-nl+NR_END;
  396. }
  397.  
  398. unsigned char *cvector(long nl, long nh)
  399. /* allocate an unsigned char vector with subscript range v[nl..nh] */
  400. {
  401.    unsigned char *v;
  402.  
  403.    v=(unsigned char *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(unsigned char)));
  404.    if (!v) nrerror("allocation failure in cvector()");
  405.    return v-nl+NR_END;
  406. }
  407.  
  408. unsigned long *lvector(long nl, long nh)
  409. /* allocate an unsigned long vector with subscript range v[nl..nh] */
  410. {
  411.    unsigned long *v;
  412.  
  413.    v=(unsigned long *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(long)));
  414.    if (!v) nrerror("allocation failure in lvector()");
  415.    return v-nl+NR_END;
  416. }
  417.  
  418. double *dvector(long nl, long nh)
  419. /* allocate a double vector with subscript range v[nl..nh] */
  420. {
  421.    double *v;
  422.  
  423.    v=(double *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(double)));
  424.    if (!v) nrerror("allocation failure in dvector()");
  425.    return v-nl+NR_END;
  426. }
  427.  
  428. float **matrix(long nrl, long nrh, long ncl, long nch)
  429. /* allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] */
  430. {
  431.    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
  432.    float **m;
  433.  
  434.    /* allocate pointers to rows */
  435.    m=(float **) malloc((size_t)((nrow+NR_END)*sizeof(float*)));
  436.    if (!m) nrerror("allocation failure 1 in matrix()");
  437.    m += NR_END;
  438.    m -= nrl;
  439.  
  440.    /* allocate rows and set pointers to them */
  441.    m[nrl]=(float *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float)));
  442.    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
  443.    m[nrl] += NR_END;
  444.    m[nrl] -= ncl;
  445.  
  446.    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
  447.  
  448.    /* return pointer to array of pointers to rows */
  449.    return m;
  450. }
  451.  
  452. double **dmatrix(long nrl, long nrh, long ncl, long nch)
  453. /* allocate a double matrix with subscript range m[nrl..nrh][ncl..nch] */
  454. {
  455.    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
  456.    double **m;
  457.  
  458.    /* allocate pointers to rows */
  459.    m=(double **) malloc((size_t)((nrow+NR_END)*sizeof(double*)));
  460.    if (!m) nrerror("allocation failure 1 in matrix()");
  461.    m += NR_END;
  462.    m -= nrl;
  463.  
  464.    /* allocate rows and set pointers to them */
  465.    m[nrl]=(double *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(double)));
  466.    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
  467.    m[nrl] += NR_END;
  468.    m[nrl] -= ncl;
  469.  
  470.    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
  471.  
  472.    /* return pointer to array of pointers to rows */
  473.    return m;
  474. }
  475.  
  476. int **imatrix(long nrl, long nrh, long ncl, long nch)
  477. /* allocate a int matrix with subscript range m[nrl..nrh][ncl..nch] */
  478. {
  479.    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
  480.    int **m;
  481.  
  482.    /* allocate pointers to rows */
  483.    m=(int **) malloc((size_t)((nrow+NR_END)*sizeof(int*)));
  484.    if (!m) nrerror("allocation failure 1 in matrix()");
  485.    m += NR_END;
  486.    m -= nrl;
  487.  
  488.  
  489.    /* allocate rows and set pointers to them */
  490.    m[nrl]=(int *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(int)));
  491.    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
  492.    m[nrl] += NR_END;
  493.    m[nrl] -= ncl;
  494.  
  495.    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
  496.  
  497.    /* return pointer to array of pointers to rows */
  498.    return m;
  499. }
  500.  
  501. float **submatrix(float **a, long oldrl, long oldrh, long oldcl, long oldch,
  502.    long newrl, long newcl)
  503. /* point a submatrix [newrl..][newcl..] to a[oldrl..oldrh][oldcl..oldch] */
  504. {
  505.    long i,j,nrow=oldrh-oldrl+1,ncol=oldcl-newcl;
  506.    float **m;
  507.  
  508.    /* allocate array of pointers to rows */
  509.    m=(float **) malloc((size_t) ((nrow+NR_END)*sizeof(float*)));
  510.    if (!m) nrerror("allocation failure in submatrix()");
  511.    m += NR_END;
  512.    m -= newrl;
  513.  
  514.    /* set pointers to rows */
  515.    for(i=oldrl,j=newrl;i<=oldrh;i++,j++) m[j]=a[i]+ncol;
  516.  
  517.    /* return pointer to array of pointers to rows */
  518.    return m;
  519. }
  520.  
  521. float **convert_matrix(float *a, long nrl, long nrh, long ncl, long nch)
  522. /* allocate a float matrix m[nrl..nrh][ncl..nch] that points to the matrix
  523. declared in the standard C manner as a[nrow][ncol], where nrow=nrh-nrl+1
  524. and ncol=nch-ncl+1. The routine should be called with the address
  525. &a[0][0] as the first argument. */
  526. {
  527.    long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1;
  528.    float **m;
  529.  
  530.    /* allocate pointers to rows */
  531.    m=(float **) malloc((size_t) ((nrow+NR_END)*sizeof(float*)));
  532.    if (!m) nrerror("allocation failure in convert_matrix()");
  533.    m += NR_END;
  534.    m -= nrl;
  535.  
  536.    /* set pointers to rows */
  537.    m[nrl]=a-ncl;
  538.    for(i=1,j=nrl+1;i<nrow;i++,j++) m[j]=m[j-1]+ncol;
  539.    /* return pointer to array of pointers to rows */
  540.    return m;
  541. }
  542.  
  543. float ***f3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
  544. /* allocate a float 3tensor with range t[nrl..nrh][ncl..nch][ndl..ndh] */
  545. {
  546.    long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
  547.    float ***t;
  548.  
  549.    /* allocate pointers to pointers to rows */
  550.    t=(float ***) malloc((size_t)((nrow+NR_END)*sizeof(float**)));
  551.    if (!t) nrerror("allocation failure 1 in f3tensor()");
  552.    t += NR_END;
  553.    t -= nrl;
  554.  
  555.    /* allocate pointers to rows and set pointers to them */
  556.    t[nrl]=(float **) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float*)));
  557.    if (!t[nrl]) nrerror("allocation failure 2 in f3tensor()");
  558.    t[nrl] += NR_END;
  559.    t[nrl] -= ncl;
  560.  
  561.    /* allocate rows and set pointers to them */
  562.    t[nrl][ncl]=(float *) malloc((size_t)((nrow*ncol*ndep+NR_END)*sizeof(float)));
  563.    if (!t[nrl][ncl]) nrerror("allocation failure 3 in f3tensor()");
  564.    t[nrl][ncl] += NR_END;
  565.    t[nrl][ncl] -= ndl;
  566.  
  567.    for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
  568.    for(i=nrl+1;i<=nrh;i++) {
  569.       t[i]=t[i-1]+ncol;
  570.       t[i][ncl]=t[i-1][ncl]+ncol*ndep;
  571.       for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
  572.    }
  573.  
  574.    /* return pointer to array of pointers to rows */
  575.    return t;
  576. }
  577.  
  578. void free_vector(float *v, long nl, long nh)
  579. /* free a float vector allocated with vector() */
  580. {
  581.    free((FREE_ARG) (v+nl-NR_END));
  582. }
  583.  
  584. void free_ivector(int *v, long nl, long nh)
  585. /* free an int vector allocated with ivector() */
  586. {
  587.    free((FREE_ARG) (v+nl-NR_END));
  588. }
  589.  
  590. void free_cvector(unsigned char *v, long nl, long nh)
  591. /* free an unsigned char vector allocated with cvector() */
  592. {
  593.    free((FREE_ARG) (v+nl-NR_END));
  594. }
  595.  
  596. void free_lvector(unsigned long *v, long nl, long nh)
  597. /* free an unsigned long vector allocated with lvector() */
  598. {
  599.    free((FREE_ARG) (v+nl-NR_END));
  600. }
  601.  
  602. void free_dvector(double *v, long nl, long nh)
  603. /* free a double vector allocated with dvector() */
  604. {
  605.    free((FREE_ARG) (v+nl-NR_END));
  606. }
  607.  
  608. void free_matrix(float **m, long nrl, long nrh, long ncl, long nch)
  609. /* free a float matrix allocated by matrix() */
  610. {
  611.    free((FREE_ARG) (m[nrl]+ncl-NR_END));
  612.    free((FREE_ARG) (m+nrl-NR_END));
  613. }
  614.  
  615. void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch)
  616. /* free a double matrix allocated by dmatrix() */
  617. {
  618.    free((FREE_ARG) (m[nrl]+ncl-NR_END));
  619.    free((FREE_ARG) (m+nrl-NR_END));
  620. }
  621.  
  622. void free_imatrix(int **m, long nrl, long nrh, long ncl, long nch)
  623. /* free an int matrix allocated by imatrix() */
  624. {
  625.    free((FREE_ARG) (m[nrl]+ncl-NR_END));
  626.    free((FREE_ARG) (m+nrl-NR_END));
  627. }
  628.  
  629. void free_submatrix(float **b, long nrl, long nrh, long ncl, long nch)
  630. /* free a submatrix allocated by submatrix() */
  631. {
  632.    free((FREE_ARG) (b+nrl-NR_END));
  633. }
  634.  
  635. void free_convert_matrix(float **b, long nrl, long nrh, long ncl, long nch)
  636. /* free a matrix allocated by convert_matrix() */
  637. {
  638.    free((FREE_ARG) (b+nrl-NR_END));
  639. }
  640.  
  641. void free_f3tensor(float ***t, long nrl, long nrh, long ncl, long nch,
  642.    long ndl, long ndh)
  643. /* free a float f3tensor allocated by f3tensor() */
  644. {
  645.    free((FREE_ARG) (t[nrl][ncl]+ndl-NR_END));
  646.    free((FREE_ARG) (t[nrl]+ncl-NR_END));
  647.    free((FREE_ARG) (t+nrl-NR_END));
  648. }
  649. /* (C) Copr. 1986-92 Numerical Recipes Software $|9`0S[)03. */
  650.